#ifndef _BOOT_LOADER_H_
#define _BOOT_LOADER_H_

#include "../../Component.h"
#include<avr/io.h>
#include<avr/interrupt.h>
#include "../../../bit/bit.h"

namespace Hardware
{
namespace Avr
{

	typedef struct BOOT_LOADER_CONFIG
	{
		unsigned char interrupt : 1;
		unsigned char readWhileWriteBusy : 1;
		unsigned char readWhileWriteReadEnable : 1;
		unsigned char bootLockBit : 1;
		unsigned char pageWrite : 1;
		unsigned char pageErase : 1;
		unsigned char enable : 1;
		unsigned char bootLockMode0 : 2;
		unsigned char bootLockMode1 : 2;
		
		
	} BootLoaderConfig;

	typedef struct BOOT_LOADER_DATA
	{
		unsigned long int address : 16; //z pointer.
		unsigned long int data : 16;
	} BootLoaderData;

	class BootLoader : public Component<BootLoaderConfig, BootLoaderData>
	{
		public :

		
		BootLoader(){}
		BootLoader(BootLoaderConfig c){configuration=c;}
		void config()
		{	
			//copy SPMCR so all writes happen at the same time
			unsigned char temp = SPMCR;
			//set interrupt
			temp = SetBit(temp, SPMIE, configuration.interrupt);
			//set busy
			temp = SetBit(temp, RWWSB,
				 configuration.readWhileWriteBusy);
			//set read while write read enable
			temp = SetBit(temp, RWWSRE,
				configuration.readWhileWriteReadEnable);
			//set bootlockbit
			temp = SetBit(temp, BLBSET, 
				 configuration.bootLockBit);
			//assign the register with all values now
			SPMCR = temp;
		}
		void run(){}
	};
}
}




#endif
